import time
from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.maximize_window()
driver.get("https://sahitest.com/demo/confirmTest.htm")
time.sleep(2)
driver.find_element(By.NAME, 'b1').click()
# 获取弹窗文字
print(driver.switch_to.alert.text)
time.sleep(2)
# 点击取消弹窗
driver.switch_to.alert.dismiss()
time.sleep(3)
driver.close()
